home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
mfgdemo
/
mfg_dsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
16KB
|
567 lines
#ifndef lint
static char SccsId[]= "@(#)mfg_dsp.c V1.14 3/15/95";
#endif
/*------------------------------------------------------------------
| file name -- display.c
|
| functions Description
| --------- -----------
| InitDisplays Initializes the SCREEN and DRAWPORTS
| TermDisplays Cleans up the SCREEN, DRAWPORTS and DISPLAY_LIST
|
| SwitchDisplay Display Manager
| OverlayPidDisplay Overlay the view.
| RemovePidDisplay Deletes the overlayed view.
|
| preload_views Preloads all views... (base and overlays)
| create_drawport Creates the drawport and add is to the table
| get_drawport Returns the previously or newly created drawport.
| load_view Loads the view and adds it to the table.
| next_display Adds a display to the list.
| prev_display Deletes a display from the list.
| reset_display Destroys the display list, reset to the top display
| create_display_list Create a DisplayList for NEXT/PREV.
| del_display_list_item Delete a display from the DisplayList.
| destroy_display_list Destroys the DisplayList.
|
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvGR.h"
#include "Tfundecl.h"
#include "mfg_vars.h"
#include "VOfundecl.h"
#include "VTfundecl.h"
#include "VUfundecl.h"
#include "GRfundecl.h"
#include "mfg_fundecl.h"
#define DEFAULT_SIZE (RECTANGLE*)NULL
#define DEFAULT_PORTION (RECTANGLE*)NULL
#define NEW_LIST (char)0
#define ADD_TO_LIST (char)1
#define DELETE_FROM_LIST (char)2
/***************** Begin Function Declarations *************/
LOCAL void preload_views V_P_((void));
LOCAL DRAWPORT create_drawport V_P_((OBJECT screen, char *viewname, RECTANGLE *where_vp));
LOCAL VIEW load_view V_P_((char *view_name));
LOCAL DRAWPORT get_drawport V_P_((char *view_name));
LOCAL DRAWPORT next_display V_P_((char *view_name));
LOCAL DRAWPORT prev_display V_P_((void));
LOCAL DRAWPORT reset_display V_P_((void));
LOCAL DISPLAY_LIST *create_display_list V_P_((void));
LOCAL void del_display_list_item V_P_((DISPLAY_LIST *display_item));
LOCAL void destroy_display_list V_P_((DISPLAY_LIST **display_info));
/***************** End Function Declarations *************/
/*-----------------------------------------------------------------
|
| InitDisplays
| Performs the initialization needed for the display.
|
| A SCREEN is opened using DVDEVICE and other attributes.
|
| create_drawport() is called to create a drawport for each
| display area. create_drawport will be called each time a
| a new views is needed by the display manager.
*/
void
InitDisplays (device)
char *device;
{
int error_code;
char buf[50];
/* Open the main window */
VUoff_copyright ();
DVscreen = TscOpenSet (device, (CHAR *) NULL,
V_WINDOW_NAME, " *** DataViews Manufacturing Demo ***",
#ifdef WINNT
V_WIN32_ICON_NAME, "mfgicon",
#ifdef DOUBLE_BUFFER
V_WIN32_DOUBLE_BUFFER, YES,
#endif /* DOUBLE_BUFFER */
#else /* Not WINNT */
V_X_EXPOSURE_BLOCK, YES,
#endif /* WINNT */
V_END_OF_LIST );
if(!DVscreen)
{
error_code=TscOpenError();
#ifdef WINNT
sprintf(buf,"Product is not validated. Error code %d.",error_code);
MessageBox(NULL,buf,"Validation Error",MB_OK);
#else
fprintf(stderr,"Product is not validated. Error code %d.",error_code);
#endif
exit(error_code);
}
/* If we couldn't open a window, exit the program */
EXIT_IF_INVALID (DVscreen, NO_DEVICE);
/* Initialize the window events */
InitSimpleEvents ();
/* Erase the "copyright" message and set the cursor */
(VOID) TscErase (DVscreen);
/* Create the drawport table needed for display management */
DpTable = VTstcreate ("View Names and DRAWPORTs", (VTSTCOMPAREFUNPTR)NULL);
/* Preload all the views... draws the top view */
preload_views ();
/* Set the active drawport to the Top View */
ActiveDrawport = get_drawport (ViewName[TOP_VIEW]);
EXIT_IF_INVALID (ActiveDrawport, NO_TOP_VIEW);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
}
/*-----------------------------------------------------------------
|
| SwitchDisplays
| Switches the view being displayed in the MONITOR AREA.
|
| The views are managed in a "DisplayList" which is
| updated according to the "choice".
| next_display() - Adds a display to the list.
| prev_display() - Deletes a display from the list.
| reset_display()- Resets the list back to the TOP_VIEW.
|
| This allows us to keep a history of where we've been.
|
| The old display is terminated before the new display is
| drawn;
*/
void
SwitchDisplay (choice, view_name)
int choice;
char *view_name;
{
DRAWPORT new_dp = NULL;
/* If they switch to the top display, reset the NEXT/PREV list */
if (view_name && STRINGS_ARE_EQUAL (view_name, ViewName[TOP_VIEW]))
choice = RESET_DISPLAY;
/* Switch displays according to the choice */
switch ((INT) choice)
{
case PREV_DISPLAY:
new_dp = prev_display ();
break;
case NEXT_DISPLAY:
new_dp = next_display (view_name);
break;
case RESET_DISPLAY:
new_dp = reset_display ();
break;
default:
break;
}
/* If we can successfully switch displays, cleanup and continue */
if (new_dp)
{
/* Erase the old display */
(VOID) TdpErase (ActiveDrawport);
if (ActiveDrawport == DrawportId[PAINT_SHOP_VIEW] && PidDrawport)
(VOID) TdpErase (PidDrawport);
/* Draw the new display */
ActiveDrawport = new_dp;
(VOID) TdpDraw (ActiveDrawport);
if (ActiveDrawport == DrawportId[PAINT_SHOP_VIEW] && PidDrawport)
(VOID) TdpDraw (PidDrawport);
}
}
/*-----------------------------------------------------------------
|
| OverlayPidDisplay
| Tries to overlay a view to the current display. The
| named view's drawport is displayed. Only one drawport
| can be active at once.
|
*/
LOCAL INT PidCount = 0;
LOCAL DRAWPORT PrevPidDrawport = 0;
void
OverlayPidDisplay (view_name)
char *view_name;
{
DRAWPORT desired_drawport;
desired_drawport = get_drawport (view_name);
if (desired_drawport)
{
if (desired_drawport != PidDrawport)
{
if (desired_drawport != PrevPidDrawport)
PidCount++;
PrevPidDrawport = PidDrawport;
PidDrawport = desired_drawport;
(VOID) TdpDraw (PidDrawport);
}
}
}
/*-----------------------------------------------------------------
|
| RemovePidDisplay
| Removes the PidDrawport if it's active and restores the area
| below the drawport.
|
*/
void RemovePidDisplay
V_P_ ((void))
{
RECTANGLE *vp, erase_vp;
if (PidDrawport)
{
/* Get the Pid drawport's area */
vp = TdpGetScreenVp (PidDrawport);
/* Convert the Pid's area to screen coordinates */
(VOID) GRvcs_to_scs (&vp->ll, &erase_vp.ll);
(VOID) GRvcs_to_scs (&vp->ur, &erase_vp.ur);
/* Erase the Pid drawport */
(VOID) TdpErase (PidDrawport);
/* Restore the obscured area */
(VOID) TscRedraw (DVscreen, &erase_vp);
/* reset the Pid Counts */
PidCount--;
if (PidCount != 0)
PidDrawport = PrevPidDrawport;
else
PidDrawport = (DRAWPORT) NULL;
PrevPidDrawport = (DRAWPORT) NULL;
}
}
/*-----------------------------------------------------------------
|
| preload_views
| The function Pre-Loads the views....
*/
LOCAL void preload_views
V_P_ ((void))
{
INT i;
VIEW view;
OBJECT dr, area_obj;
DRAWPORT dp;
RECTANGLE vp, dummy;
/* For all the main views... load the view, rebind its data,
| create a drawport, add the drawport to the symbol table.
| Draw the top view!
*/
for (i = 0; i < NUM_DISPLAYS; i++)
{
DrawportId[i] = create_drawport (DVscreen, ViewName[i], (RECTANGLE *) NULL);
if (i == 0)
TdpDraw (DrawportId[i]);
}
/* For all the Pid views... create a drawport using the area
| defined by the pid.area object in the PAINT_SHOP_VIEW.
*/
dp = get_drawport (ViewName[PAINT_SHOP_VIEW]);
view = TdpGetView (dp);
dr = TviGetDrawing (view);
area_obj = TdrGetNamedObject (dr, "pid.area");
(VOID) VOobBox (area_obj, &vp, &dummy);
(VOID) TdpWorldToScreen (dp, &vp.ll, &vp.ll);
(VOID) TdpWorldToScreen (dp, &vp.ur, &vp.ur);
(VOID) GRscs_to_vcs (&vp.ll, &vp.ll);
(VOID) GRscs_to_vcs (&vp.ur, &vp.ur);
for (i = 0; i < NUM_PIDS; i++)
(VOID) create_drawport (DVscreen, PidName[i], &vp);
PidDrawport = NULL;
}
/*-----------------------------------------------------------------
|
| create_drawport
| The function creates a drawport in the specified area to
| display the specified view.
|
| The drawport is added to the symbol tables for easy
| access by the display manager routines.
|
| We call RebindData() for all the dynamic objects. This will
| see if the variable is being controlled by the application and
| rebind it if necessary.
|
| We call SetupButtons(). This will setup a Service Function for
| the button input objects.
*/
LOCAL DRAWPORT
create_drawport (screen, viewname, where_vp)
OBJECT screen;
char *viewname;
RECTANGLE *where_vp;
{
VIEW view;
DRAWPORT drawport = NULL;
RECTANGLE what_vp, dummy;
/* Load the view */
view = load_view (viewname);
if (view)
{
if (!where_vp)
drawport = TdpCreate (screen, view,
DEFAULT_SIZE, DEFAULT_PORTION);
else
{
/* Get the bounding box around the objects in the view */
(VOID) VOobBox (TviGetDrawing (view), &what_vp, &dummy);
drawport = TdpCreateStretch (screen, view, where_vp, &what_vp);
}
/* Call RebindData() to rebind to application data */
RebindData (view); /* found in mfg_rebind.c */
/* Call SetupButtons() to post service function for button handling */
SetupButtons (view); /* found in mfg_events.c */
/* Add the drawport to the table */
(VOID) VTstsninsert (DpTable, StrClone (viewname), (INT *) drawport);
}
return drawport;
}
/*-----------------------------------------------------------------
|
| load_view
| Loads the view and rebinds its data. If the view can't be
| loaded, return NULL.
*/
LOCAL VIEW
load_view (view_name)
char *view_name;
{
VIEW view = NULL;
/* Load the view and add it to the table */
view = TviLoad (view_name);
if (view)
{
/* Rebind the dyanmic object's variables to real-time data */
RebindData (view); /* found in mfg_rebind.c */
}
return view;
}
/*-----------------------------------------------------------------
|
| get_drawport
| Returns the drawport associated with the view_name. If the
| drawport doesn't exist, it creates one.
*/
LOCAL DRAWPORT
get_drawport (view_name)
char *view_name;
{
SYMNODE key;
/* See if the drawport is already in the Drawport Table */
key = VTstkeyfind (DpTable, view_name);
if (key)
return (DRAWPORT) VTsnvalue (key);
else
return create_drawport (DVscreen, view_name, (RECTANGLE *) NULL);
}
/*-----------------------------------------------------------------
|
| next_display
| Tries to add a display to the DisplayList. If the view can't
| be displayed, returns DV_FAILURE, else DV_SUCCESS.
|
*/
LOCAL DRAWPORT
next_display (view_name)
char *view_name;
{
DISPLAY_LIST *prev_display;
DRAWPORT dp;
/* Get the drawport associated with the view */
dp = get_drawport (view_name);
if (dp)
{
/* If the list doesn't exist yet, create it.
|
| Make the current list top the previous display. Then,
| make the new display the list top. */
if (!DisplayList)
{
prev_display = create_display_list ();
prev_display->drawport = ActiveDrawport;
}
else
prev_display = DisplayList;
DisplayList = create_display_list ();
DisplayList->drawport = dp;
DisplayList->prev = prev_display;
}
return dp;
}
/*-----------------------------------------------------------------
|
| prev_display
| If their is a previous display, make it the top and
| deletes the current from the list.
*/
LOCAL DRAWPORT prev_display
V_P_ ((void))
{
DISPLAY_LIST *prev_display;
/* Make sure we have a list and a previous display before
| you make the previous display the top.
*/
if (DisplayList && DisplayList->prev)
{
prev_display = DisplayList->prev;
del_display_list_item (DisplayList);
DisplayList = prev_display;
return DisplayList->drawport;
}
else
return (DRAWPORT) NULL;
}
/*-----------------------------------------------------------------
|
| reset_display
| Resets the Display List, deletes the previous list and makes
| the TOP_VIEW the beginning of the list.
*/
LOCAL DRAWPORT reset_display
V_P_ ((void))
{
/* Destroy the DisplayList */
destroy_display_list (&DisplayList);
/* return the Active Drawport to the Top View */
return get_drawport (ViewName[TOP_VIEW]);
}
/*-----------------------------------------------------------------
|
| create_display_list - Allocates and initializes a DISPLAY_LIST.
*/
LOCAL DISPLAY_LIST *create_display_list
V_P_ ((void))
{
DISPLAY_LIST *display_info;
display_info = (DISPLAY_LIST *) S_ALLOC ((LONG) sizeof (DISPLAY_LIST));
display_info->drawport = (DRAWPORT) NULL;
display_info->prev = (DISPLAY_LIST *) NULL;
return display_info;
}
/*-----------------------------------------------------------------
|
| del_display_list_item - Frees a DISPLAY_LIST item.
*/
LOCAL void
del_display_list_item (display_item)
DISPLAY_LIST *display_item;
{
S_FREE ((CHAR *) display_item);
}
/*-----------------------------------------------------------------
|
| destroy_display_list - Destroys the DISPLAY_LIST by freeing each item.
*/
LOCAL void
destroy_display_list (display_info)
DISPLAY_LIST **display_info;
{
DISPLAY_LIST *info, *prev;
info = *display_info;
while (info)
{
prev = info->prev;
del_display_list_item (info);
info = prev;
}
*display_info = NULL;
}
/*-----------------------------------------------------------------
|
| TermDisplays
| Performs the termination and clean up needed for the display
| components. This balances InitDisplays().
|
| The Drawport and View Tables are "traversed" to clean up
| the views and drawports. We also clean up the table as we go.
| The AreaCoords used to define drawport areas are "freed". The
| display manager's DisplayList is destroyed. Finally, the screen
| is erased and closed.
*/
void TermDisplays
V_P_ ((void))
{
CHAR *viewname;
SYMNODE node;
VIEW view;
DRAWPORT dp;
/* Destroy the display info */
while (VTstlen (DpTable) > 0)
{
node = VTstsnget (DpTable, 0);
viewname = VTsnkey (node);
S_FREE (viewname);
dp = (DRAWPORT) VTsnvalue (node);
view = TdpGetView (dp);
(VOID) TdpDestroy (dp);
(VOID) TviDestroy (view);
VTstsnremove (DpTable, node);
}
VTstdestroy (DpTable);
/* Destroy the Display List */
destroy_display_list (&DisplayList);
/* Destroy, Erase and Close the Windows */
(VOID) TscClose (DVscreen);
}